1 package activity;
2
3 import java.lang.*;
4 import javax.swing.*;
5 import java.awt.*;
6 import javax.swing.border.*;
7 import java.awt.
event.*;
8 import attr.*;

9
10 public
class MyProfileActivity extends JFrame implements ActionListener {
11     
private JPanel panel;
12     
private JButton buttonEdit, buttonBack, buttonLogout, buttonSubmit, buttonPass, buttonDelete;
13     
private JFrame backActivity;
14     
private User usr;
15     
private Employee employee;
16     
private Customer customer;
17     
private JLabel title, header, usernameLabel, nameLabel, phoneLabel, addressLabel;
18     
private JTextField nameTF, phoneTF1, phoneTF2, addressTF;
19     
private JLabel roleLabel, salaryLabel;
20     
public MyProfileActivity(JFrame activity, Customer customer) {
21         super(
"My Profile");
22         
23         
this.setSize(Theme.GUI_WIDTH, Theme.GUI_HEIGHT);
24         
this.setResizable(false);
25         
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
26         
this.setLocationRelativeTo(null);
27         
28         panel =
new JPanel();
29         panel.setLayout(
null);
30         panel.setBackground(Theme.BACKGROUND_PANEL);
31         
32         backActivity = activity;
33         
this.customer = customer;
34         
this.usr = (User) customer;
35         
36         title =
new JLabel("My Profile");
37         title.setBounds(
30, 40, 260,75);
38         title.setOpaque(
true);
39         title.setBorder(
new EmptyBorder(0,20,0,0));
40         title.setFont(Theme.FONT_TITLE);
41         title.setForeground(Theme.COLOR_TITLE);
42         panel.
add(title);
43         
44         buttonEdit =
new JButton("Edit Profile");
45         buttonEdit.setBounds(
60, 330, 120, 30);
46         buttonEdit.setFont(Theme.FONT_BUTTON);
47         buttonEdit.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
48         buttonEdit.setForeground(Theme.COLOR_BUTTON_PRIMARY);
49         buttonEdit.addActionListener(
this);
50         panel.
add(buttonEdit);
51         
52         buttonSubmit =
new JButton("Submit");
53         buttonSubmit.setBounds(
60, 330, 120, 30);
54         buttonSubmit.setFont(Theme.FONT_BUTTON);
55         buttonSubmit.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
56         buttonSubmit.setForeground(Theme.COLOR_BUTTON_PRIMARY);
57         buttonSubmit.setVisible(
false);
58         buttonSubmit.addActionListener(
this);
59         panel.
add(buttonSubmit);
60         
61         buttonPass =
new JButton("Change Password");
62         buttonPass.setBounds(Theme.GUI_WIDTH-
180, 115, 160, 30);
63         buttonPass.setFont(Theme.FONT_BUTTON);
64         buttonPass.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
65         buttonPass.setForeground(Theme.COLOR_BUTTON_PRIMARY);
66         buttonPass.addActionListener(
this);
67         panel.
add(buttonPass);
68         
69         buttonDelete =
new JButton("Delete Account");
70         buttonDelete.setBounds(Theme.GUI_WIDTH-
180, 150, 160, 30);
71         buttonDelete.setFont(Theme.FONT_BUTTON);
72         buttonDelete.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
73         buttonDelete.setForeground(Theme.COLOR_BUTTON_PRIMARY);
74         buttonDelete.addActionListener(
this);
75         panel.
add(buttonDelete);
76         
77         buttonLogout =
new JButton("Logout");
78         buttonLogout.setBounds(Theme.GUI_WIDTH-
140, 40, Theme.BUTTON_PRIMARY_WIDTH, 30);
79         buttonLogout.setFont(Theme.FONT_BUTTON);
80         buttonLogout.setBackground(Color.WHITE);
81         buttonLogout.setForeground(Theme.COLOR_TITLE);
82         buttonLogout.addActionListener(
this);
83         panel.
add(buttonLogout);
84         
85         buttonBack =
new JButton("Back");
86         buttonBack.setBounds(Theme.GUI_WIDTH-
140, 80, Theme.BUTTON_PRIMARY_WIDTH, 30);
87         buttonBack.setFont(Theme.FONT_BUTTON);
88         buttonBack.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
89         buttonBack.setForeground(Theme.COLOR_BUTTON_PRIMARY);
90         buttonBack.addActionListener(
this);
91         panel.
add(buttonBack);
92         
93         usernameLabel =
new JLabel("User ID: "+customer.getUserId());
94         usernameLabel.setBounds(
60, 140, 440, 30);
95         usernameLabel.setFont(Theme.FONT_REGULAR);
96         panel.
add(usernameLabel);
97         
98         nameLabel =
new JLabel("Name: ");
99         nameLabel.setBounds(
60, 190, 440, 30);
100         nameLabel.setFont(Theme.FONT_REGULAR);
101         panel.
add(nameLabel);
102         
103         phoneLabel =
new JLabel("Phone No: ");
104         phoneLabel.setBounds(
60, 240, 440, 30);
105         phoneLabel.setFont(Theme.FONT_REGULAR);
106         panel.
add(phoneLabel);
107         
108         nameTF =
new JTextField(customer.getCustomerName());
109         nameTF.setBounds(
180, 190, 220, 30);
110         nameTF.setFont(Theme.FONT_INPUT);
111         nameTF.setEnabled(
false);
112         nameTF.setDisabledTextColor(Color.BLACK);
113         panel.
add(nameTF);
114         
115         phoneTF1 =
new JTextField("+880");
116         phoneTF1.setBounds(
180, 240, 40, 30);
117         phoneTF1.setFont(Theme.FONT_INPUT);
118         phoneTF1.setEnabled(
false);
119         phoneTF1.setDisabledTextColor(Color.BLACK);
120         panel.
add(phoneTF1);
121         
122         phoneTF2 =
new JTextField(customer.getPhoneNumber().substring(4));
123         phoneTF2.setBounds(
220, 240, 180, 30);
124         phoneTF2.setFont(Theme.FONT_INPUT);
125         phoneTF2.setEnabled(
false);
126         phoneTF2.setDisabledTextColor(Color.BLACK);
127         panel.
add(phoneTF2);
128         
129         addressTF =
new JTextField(customer.getAddress());
130         addressTF.setBounds(
180, 290, 220, 30);
131         addressTF.setEnabled(
false);
132         addressTF.setFont(Theme.FONT_INPUT);
133         addressTF.setDisabledTextColor(Color.BLACK);
134         panel.
add(addressTF);
135         
136         addressLabel =
new JLabel("Address: ");
137         addressLabel.setBounds(
60, 290, 440, 30);
138         addressLabel.setFont(Theme.FONT_REGULAR);
139         panel.
add(addressLabel);
140         
141         header =
new JLabel();
142         header.setBackground(Theme.BACKGROUND_HEADER);
143         header.setOpaque(
true);
144         header.setBounds(
0, 0, Theme.GUI_WIDTH, 75);
145         panel.
add(header);
146         
147         
this.add(panel);
148     }
149     
150     
public MyProfileActivity(JFrame activity, Employee employee) {
151         super(
"My Profile");
152         
153         
this.setSize(Theme.GUI_WIDTH, Theme.GUI_HEIGHT);
154         
this.setResizable(false);
155         
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
156         
this.setLocationRelativeTo(null);
157         
158         panel =
new JPanel();
159         panel.setLayout(
null);
160         panel.setBackground(Theme.BACKGROUND_PANEL);
161         
162         backActivity = activity;
163         
this.employee = employee;
164         
this.usr = (User) employee;
165         
166         title =
new JLabel("My Profile");
167         title.setBounds(
30, 40, 260,75);
168         title.setOpaque(
true);
169         title.setBorder(
new EmptyBorder(0,20,0,0));
170         title.setFont(Theme.FONT_TITLE);
171         title.setForeground(Theme.COLOR_TITLE);
172         panel.
add(title);
173         
174         buttonEdit =
new JButton("Edit Profile");
175         buttonEdit.setBounds(
60, 380, 120, 30);
176         buttonEdit.setFont(Theme.FONT_BUTTON);
177         buttonEdit.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
178         buttonEdit.setForeground(Theme.COLOR_BUTTON_PRIMARY);
179         buttonEdit.addActionListener(
this);
180         panel.
add(buttonEdit);
181         
182         buttonSubmit =
new JButton("Submit");
183         buttonSubmit.setBounds(
60, 380, 120, 30);
184         buttonSubmit.setFont(Theme.FONT_BUTTON);
185         buttonSubmit.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
186         buttonSubmit.setForeground(Theme.COLOR_BUTTON_PRIMARY);
187         buttonSubmit.setVisible(
false);
188         buttonSubmit.addActionListener(
this);
189         panel.
add(buttonSubmit);
190         
191         buttonPass =
new JButton("Change Password");
192         buttonPass.setBounds(Theme.GUI_WIDTH-
180, 115, 160, 30);
193         buttonPass.setFont(Theme.FONT_BUTTON);
194         buttonPass.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
195         buttonPass.setForeground(Theme.COLOR_BUTTON_PRIMARY);
196         buttonPass.addActionListener(
this);
197         panel.
add(buttonPass);
198         
199         buttonLogout =
new JButton("Logout");
200         buttonLogout.setBounds(Theme.GUI_WIDTH-
140, 40, Theme.BUTTON_PRIMARY_WIDTH, 30);
201         buttonLogout.setFont(Theme.FONT_BUTTON);
202         buttonLogout.setBackground(Color.WHITE);
203         buttonLogout.setForeground(Theme.COLOR_TITLE);
204         buttonLogout.addActionListener(
this);
205         panel.
add(buttonLogout);
206         
207         buttonBack =
new JButton("Back");
208         buttonBack.setBounds(Theme.GUI_WIDTH-
140, 80, Theme.BUTTON_PRIMARY_WIDTH, 30);
209         buttonBack.setFont(Theme.FONT_BUTTON);
210         buttonBack.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
211         buttonBack.setForeground(Theme.COLOR_BUTTON_PRIMARY);
212         buttonBack.addActionListener(
this);
213         panel.
add(buttonBack);
214         
215         usernameLabel =
new JLabel("User ID: "+employee.getUserId());
216         usernameLabel.setBounds(
60, 140, 440, 30);
217         usernameLabel.setFont(Theme.FONT_REGULAR);
218         panel.
add(usernameLabel);
219         
220         nameLabel =
new JLabel("Name: ");
221         nameLabel.setBounds(
60, 190, 440, 30);
222         nameLabel.setFont(Theme.FONT_REGULAR);
223         panel.
add(nameLabel);
224         
225         phoneLabel =
new JLabel("Phone No: ");
226         phoneLabel.setBounds(
60, 240, 440, 30);
227         phoneLabel.setFont(Theme.FONT_REGULAR);
228         panel.
add(phoneLabel);
229         
230         roleLabel =
new JLabel("Role: "+employee.getRole());
231         roleLabel.setBounds(
60, 290, 440, 30);
232         roleLabel.setFont(Theme.FONT_REGULAR);
233         panel.
add(roleLabel);
234         
235         salaryLabel =
new JLabel("Salary: "+employee.getSalary());
236         salaryLabel.setBounds(
60, 340, 440, 30);
237         salaryLabel.setFont(Theme.FONT_REGULAR);
238         panel.
add(salaryLabel);
239         
240         
241         nameTF =
new JTextField(employee.getEmployeeName());
242         nameTF.setBounds(
180, 190, 220, 30);
243         nameTF.setFont(Theme.FONT_INPUT);
244         nameTF.setEnabled(
false);
245         nameTF.setDisabledTextColor(Color.BLACK);
246         panel.
add(nameTF);
247         
248         phoneTF1 =
new JTextField("+880");
249         phoneTF1.setBounds(
180, 240, 40, 30);
250         phoneTF1.setFont(Theme.FONT_INPUT);
251         phoneTF1.setEnabled(
false);
252         phoneTF1.setDisabledTextColor(Color.BLACK);
253         panel.
add(phoneTF1);
254         
255         phoneTF2 =
new JTextField(employee.getPhoneNumber().substring(4));
256         phoneTF2.setBounds(
220, 240, 180, 30);
257         phoneTF2.setFont(Theme.FONT_INPUT);
258         phoneTF2.setEnabled(
false);
259         phoneTF2.setDisabledTextColor(Color.BLACK);
260         panel.
add(phoneTF2);
261         
262         header =
new JLabel();
263         header.setBackground(Theme.BACKGROUND_HEADER);
264         header.setOpaque(
true);
265         header.setBounds(
0, 0, Theme.GUI_WIDTH, 75);
266         panel.
add(header);
267         
268         
this.add(panel);
269     }
270     
271     
public void actionPerformed(ActionEvent ae) {
272         
if (ae.getSource().equals(buttonBack)) {
273             
this.setVisible(false);
274             backActivity.setVisible(
true);
275         }
276         
else if (ae.getSource().equals(buttonLogout)) {
277             
this.setVisible(false);
278             
new LoginActivity().setVisible(true);
279         }
280         
else if (ae.getSource().equals(buttonEdit)) {
281             buttonEdit.setVisible(
false);
282             buttonSubmit.setVisible(
true);
283             nameTF.setEnabled(
true);
284             phoneTF2.setEnabled(
true);
285             
if (customer!=null)
286                 addressTF.setEnabled(
true);
287         }
288         
else if (ae.getSource().equals(buttonSubmit)) {
289             
290             
if (customer!=null) {
291                 addressTF.setEnabled(
false);
292                 
try {
293                     customer.updateCustomer(nameTF.getText().trim(), Integer.parseInt(phoneTF2.getText()), addressTF.getText().trim());
294                     buttonEdit.setVisible(
true);
295                     buttonSubmit.setVisible(
false);
296                     nameTF.setEnabled(
false);
297                     phoneTF2.setEnabled(
false);
298                 }
299                 
catch (NumberFormatException e) {
300                     JOptionPane.showMessageDialog(
null,"Invalid Number!");
301                 }
302             }
303             
else if (employee!=null) {
304                 
try {
305                     employee.updateEmployee(nameTF.getText().trim(), Integer.parseInt(phoneTF2.getText()), employee.getRole(), employee.getSalary());
306                     buttonEdit.setVisible(
true);
307                     buttonSubmit.setVisible(
false);
308                     nameTF.setEnabled(
false);
309                     phoneTF2.setEnabled(
false);
310                 }
311                 
catch (NumberFormatException e) {
312                     JOptionPane.showMessageDialog(
null,"Invalid number!");
313                 }
314             }
315         }
316         
else if (ae.getSource().equals(buttonPass)) {
317             
new ChangePasswordActivity(this.usr).setVisible(true);
318         }
319         
else if (ae.getSource().equals(buttonDelete)) {
320             
int input = JOptionPane.showConfirmDialog(null, "Sure to Delete?", "Delete "+customer.getUserId()+"?", JOptionPane.YES_NO_OPTION);
321             
if (input == 0) {
322                 customer.deleteCustomer();
323                 
this.setVisible(false);
324                 
new LoginActivity().setVisible(true);
325             }
326             
else {}
327         }
328         
else {}
329     }
330 }


Gõ tìm kiếm nhanh...